package com.monolithiot.notifier.controller;

import com.monolithiot.notifier.common.vo.BasicJsonResponse;
import com.monolithiot.notifier.common.vo.VerifySms;
import com.monolithiot.notifier.service.SentSmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 2018/12/22 Create by 郭文梁
 * SmsController
 * 短信相关控制器
 *
 * @author 郭文梁
 * @date 2018/12/22
 */
@RestController
@RequestMapping("/sms")
public class SmsController {
    private final SentSmsService sentSmsService;

    @Autowired
    public SmsController(SentSmsService sentSmsService) {
        this.sentSmsService = sentSmsService;
    }

    /**
     * 发送短信验证码
     *
     * @return BJR with verify code
     */
    @PostMapping("/_send-verify-code")
    public BasicJsonResponse<VerifySms> send(String number) {
        VerifySms verifySms = sentSmsService.sendVerifyCode(number);
        if (verifySms == null) {
            return BasicJsonResponse.systemError("发送验证短信失败");
        }
        return BasicJsonResponse.ok(verifySms);
    }
}
